Carbon

     

Custom Scheduler

The Thread Manager allows you to install a custom scheduling function that works in conjunction with the Thread Manager default scheduling mechanism. You install the custom scheduling function with the SetThreadScheduler function. Figure 3 shows how the custom scheduler works with the default Thread Manager scheduling mechanism.

Figure 3Thread Manager default and custom scheduling mechanisms

When a yield or other Thread Manager call triggers a reschedule, the Thread Manager calls the custom scheduling function and passes it a scheduler information structure. This structure has four fields; the first contains the size of the structure and allows for expansion in the future. The next two fields are thread IDs that identify the current thread and the thread that the application has selected to run next. The final field was to identify a cooperative thread that was interrupted by a preemptive thread. However, because it no longer supports preemptive threads, the Thread Manager always passes the kNoThreadID constant for this field.

The custom scheduling function can use this information to determine which thread to schedule next. It returns to the default scheduling mechanism the thread ID of the next thread to schedule and the Thread Manager does the actual scheduling.


© 2000 Apple Computer, Inc. – (Last Updated 09 May 00)